/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GoMail;

import DlinkedList.MyDList;
import Queue.MyQueue;
import account.Account;
import folders2.ProjectFile;
import folders2.UserFolders2;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import message.Attachment;
import message.Message;
import message.MessageFolder;

/**
 *
 * @author Administrator
 */
public interface MailUserOperationsInterface {

    /**
     * this method is used to add new contact to user
     * @param c new contact
     */
    void addContact(Contacts c);

    /**
     * this method is used to create new custom folder in user folder
     * @param FolderName new custom folder name
     */
    void createFolder(String FolderName);

    /**
     * this method is used to delete contact by the holping of searchContacts(String name) method
     * @param contactName contact name
     */
    void deleteContact(String contactName);

    /**
     * this method is used to delete any folder from user folders
     * (in our case we use it to delete cutom folder)
     * @param folderName folder name
     */
    void deleteFolder(String folderName);

    /**
     * I use this method to delete any message in any folder
     * and transfer deleted one to trash folder
     * @param mess message which will be deleted
     * @throws java.io.IOException
     */
    void deleteMessage(MessageFolder mess) throws IOException;

    MessageFolder[] displaymessage() throws IOException;

    /**
     * This method is used to download attachment from message to any path
     * @param downloadPath path of location where message will be downloaded
     * @param source message folder
     * @throws java.io.IOException
     */
    void downloadAttachment(String downloadPath, File source) throws IOException;

    /**
     * This method is used to checks this message is realized sender filters data or not
     * @param m reference or object of type message folder
     * @return result of type integer
     * returns 1 if this message is filters and trasfer to it correct filter folder
     * returns 0 if there are no filters on it
     * @throws java.io.IOException
     */
    int filterBySender(MessageFolder m) throws IOException;

    /**
     * This method is used to checks this message is realized subject filters data or not
     * @param m reference or object of type message folder
     * @return result of type integer
     * returns 1 if this message is filters and trasfer to it correct filter folder
     * returns 0 if there are no filters on it
     * @throws java.io.IOException
     */
    int filterBySubject(MessageFolder m) throws IOException;

    /**
     * this method is used to find contact by the holping of searchContacts(String name) method
     * @param name contact name
     * @return returns contact which contains contact informations else returns null
     */
    Contacts findContact(String name);

    /**
     * this method i use it to loading user data(account and reference to user folders)
     * after verfying from this user is exist in our server from users file
     * @param userId  userName
     * @param root  root folder which contains all users folders
     * @throws java.io.IOException
     */
    void findUser(String userId, ProjectFile root) throws IOException;

    /**
     * get user contact list
     * @return doubly linked list contains all users contacts and thier mails
     */
    MyDList getContactsList();

    /**
     * method to get filters user list
     * @return
     */
    MyDList getFilterList();

    /**
     * get list that contains ten message that will be loaded from any user folder
     * @return list of messages (doubliy linked list)
     */
    MyDList getMessage();

    /**
     * I use this method to read message data from message list which loaded in program
     * @param s message list which contains ten loaded messages
     * @param messageSubject message subject which appear to user
     * @return requested folder if it is found else returns null
     */
    MessageFolder getMessageBySubject(MyDList s, String messageSubject);

    /**
     * get object ref which contains the index of last messsage loaded in the list
     * @return
     */
    Object getRef();

    /**
     * get list that contains all sent messages(nearly i don't use it)
     * @return queue list of sent messages
     */
    MyQueue getSendMessage();

    /**
     * get user data (folders and account) from this object
     * @return MailUser object
     */
    MailUser getUser();

    /**
     * This method is used to load message folder from any folder
     * and put them into messageFolder[] array
     * @param folderName fodler name which we want to read messages from it
     * @return MessageFolder[] that contains all files if folder name is wrong
     * i.e folder doesn't exist returns null
     * @throws java.io.IOException
     */
    MessageFolder[] loadAllMailsFormFolder(String folderName) throws IOException;

    /**
     * This method is used to load messages from array of messages that contains all message
     * to message doubly linked list load only 10 messages
     * @param all array that contains all messages of folder
     * that returns from loadAllMailsFormFolder(String folderName)
     * @param key key to determine which ten message will be read
     * when key = 0 read first ten message
     * key = 1 read next ten messages
     * key  = 2 read previous ten messages
     */
    void loadMessagesIntoList(MessageFolder[] all, int key);

    /**
     * This method is used to send same message to multiple users
     * by take array os receivers and return array of messages each message with different receiver
     * @param messageSubject subject of message
     * @param receivers array of receivers
     * @return array of messages each message with different receiver
     * @throws java.io.IOException
     */
    Message[] makeMultipleMessages(String messageSubject, String[] receivers) throws IOException;

    void moveMessageTo(ProjectFile to, ProjectFile source, String messageName) throws IOException;

    /**
     * I use this method to transfer send messages to this user from temp folder to user folder
     * during tranfer sent messages method checks if there are any filters in this message
     * if there are any filters message is transfered to thespecified folder to that filter
     * else message tensfer to user inbox
     * @param source temp folder
     * @param messageCount number of messages sent to this user
     * @throws java.io.IOException
     */
    void moveMessageToUserFolder(ProjectFile source, int messageCount) throws IOException;

    /**
     * This method is used to read user mail contact list from contact file
     * and put them to contact list
     * @param f contact file
     * @throws java.io.IOException
     */
    void readContactData(File f) throws IOException;

    /**
     * This method is used to read filters data which put by user
     * @param f filter file
     * @throws java.io.IOException
     */
    void readFilterData(File f) throws IOException;

    MessageFolder readMessage(String name);

    /**
     * This method is used to remove hidden files which are loaded with user folder and unwanted to use
     * @param filesArray array of user files and folders
     * @return new array that doesn't contains any hidden folder
     */
    File[] removeHiddenFiles(File[] filesArray);

    /**
     * This method is used to rename any folder
     * @param oldName old name of this folder
     * @param newName new name
     * @throws java.io.IOException
     */
    void renameFolder(String oldName, String newName) throws IOException;

    /**
     * This method is used to search messages by specified messages date
     * and added them to messages doubly linked list
     * @param allSms all messages in specified folder
     * @param dateForm searched date
     * @throws java.text.ParseException
     */
    void searchingByDate(MessageFolder[] allSms, String dateForm) throws ParseException;

    /**
     * This method is used to search messages by specified messages sender
     * and added them to messages doubly linked list
     * @param allSms all messages in specified folder
     * @param senderMail sender mail
     */
    void searchingBySender(MessageFolder[] allSms, String senderMail);

    /**
     * This method is used to search messages by specified messages subject
     * and added them to messages doubly linked list
     * @param allSms all messages in specified folder
     * @param messageSubject specified message subject
     */
    void searchingBySubject(MessageFolder[] allSms, String messageSubject);

    /**
     * This method is used to send message or copy sent message to parent folder
     * @param parent parent folder such as temp folder , sent folder , inbox folder
     * @param text message text
     * @param attach message attachments
     * @param s array of messages which each element contains message informations(such that name, subject, sender ........)
     * this array of message is resulting from makeMultipleMessages(String messageSubject,String[]receivers) method
     * @throws java.io.IOException
     */
    void sendMultipleMessages(File parent, String text, Attachment attach, Message[] s) throws IOException;

    /**
     * set user contact list by change old one by new list of contacts
     * @param contactsList new doubly linked list of contacts
     */
    void setContactsList(MyDList contactsList);

    /**
     * set filter list
     * @param filterList new filter list
     */
    void setFilterList(MyDList filterList);

    /**
     * this method is called by findUser to set references to user folders &
     * account information from account file
     * and filter informations and  contact informations
     * @param f main user folder that contians all folders and files about this user
     * @param u Object of UserFolder to set its references and then give it to the MailuserOperations in privios method
     * @param c user account to st its data(first name ,lastname ...............etc)
     * @throws java.io.IOException
     */
    void setFoldersRef(File f, UserFolders2 u, Account c) throws IOException;

    /**
     * set messages list
     * @param message new messages list
     */
    void setMessage(MyDList message);

    /**
     * set index of last message loaded
     * @param ref new index
     */
    void setRef(Object ref);

    /**
     * set queue to new queue with new messages
     * @param sendMessage new queue
     */
    void setSendMessage(MyQueue sendMessage);

    /**
     * set user data (folders and account) from this object
     * @param user
     */
    void setUser(MailUser user);

    /**
     * This method is used to sort messages by attachment
     * checks whether message contains attachment or not
     * @param allSms all messages in specified folder
     * @return sorted array according to contain attachments or not
     */
    MessageFolder[] sortingByAttachment2(MessageFolder[] allSms) throws Exception;

    /**
     * This method is used to sort messages by senders
     * @param allSms all messages in specified folder
     * @return sorted array according to senders
     */
    MessageFolder[] sortingBySender(MessageFolder[] allSms);

    /**
     * This method is used to sort messages by subject
     * @param allSms all messages in specified folder
     * @return sorted array according to subject
     */
    MessageFolder[] sortingBySubject(MessageFolder[] allSms);

    /**
     * This method is used to write contact data
     * @throws java.io.IOException
     */
    void writeContactFile() throws IOException;

    /**
     * This method is used to write filter data i use it when user exist from server
     * @throws java.io.IOException
     */
    void writeFilterFile() throws IOException;

}
